//
//  ProfileViewReactor.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/5/10.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import UIKit
import ReactorKit

class ProfileViewReactor: Reactor {

    // represent user actions
     enum Action {
       case refreshFollowingStatus(Int)
       case follow(Int)
       case refresh
     }

     // represent state changes
     enum Mutation {
       case setFollowing(Bool)
     }

     // represents the current view state
     struct State {
       var isFollowing: Bool = false
     }

     let initialState: State = State()

    func mutate(action: Action) -> Observable<Mutation> {
        switch action {
        case .refresh:
            return Observable.just(Mutation.setFollowing(true))
        case .refreshFollowingStatus(_):
            return Observable.just(Mutation.setFollowing(true))
        case .follow(_):
            return Observable.just(Mutation.setFollowing(true))
        }
    }

    // Mutation -> State
    func reduce(state: State, mutation: Mutation) -> State {
      var state = state
      switch mutation {
      case .setFollowing(_):
        state.isFollowing = !state.isFollowing
      }
      return state
    }

}
